package com.example.yeujian5.yuejian5.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.example.yeujian5.yuejian5.Interface.generalFunction;
import com.example.yeujian5.yuejian5.R;
import com.example.yeujian5.yuejian5.adapter.HomeAdapter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by wangmengmeng on 2017/9/28.
 */

public class TrainFragment extends Fragment{

    private View view=null;
    private TabLayout tabs;
    private ViewPager viewPager;
    private List<String> mTitle = new ArrayList<String>();
    private List<Fragment> mFragment = new ArrayList<Fragment>();

    //轮播图
    Context context;
    private ConvenientBanner convenient;//顶部广告栏控件'
    private LinearLayout li;
    private ViewGroup.LayoutParams i;
    private String[] images = {
            "http://172.24.10.175/workout/Uploads/train//thumb//20171107//thumb_20171107110146_684922749.jpg",
            "http://172.24.10.175/workout/Uploads/train//thumb//20171107//thumb_20171107110137_1290823085.jpg"
//            "http://i3.meishichina.com/attachment/recipe/201203/p320_201203302229311333492101.JPG",
//            "http://i3.meishichina.com/attachment/recipe/201203/p320_201203302229311333492101.JPG"

    };
    List<String> img = Arrays.asList(images);


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view =  inflater.inflate(R.layout.train, container, false);

        initViews();
        new generalFunction().setCarousel(context, convenient, img, i.width, i.height);

        initData();

        HomeAdapter adapter = new HomeAdapter(getChildFragmentManager(), mTitle, mFragment);
        viewPager.setAdapter(adapter);
        //为TabLayout设置ViewPager
        tabs.setupWithViewPager(viewPager);

        return view;
    }



    private void initViews() {

        tabs = (TabLayout) view.findViewById(R.id.tab02);
        viewPager = (ViewPager) view.findViewById(R.id.viewPager);

        //轮播图
        context=getActivity();
        li = view.findViewById(R.id.top);
        convenient = view.findViewById(R.id.convenientBanner);
        i = li.getLayoutParams();//获取布局参数
        Display d = getActivity().getWindowManager().getDefaultDisplay();//获取屏幕参数
        i.height = d.getHeight() / 3;//给轮播图设置高度（/3代表是全屏的3分之一）
        i.width = d.getWidth();//给轮播图设置宽度
        convenient=view.findViewById(R.id.convenientBanner);

    }



    private void initData(){
        mTitle.add("全部");
        mTitle.add("入门");
        mTitle.add("菜鸟");
        mTitle.add("进阶");
        mFragment.add(new Train_allFragment());
        mFragment.add(new Train_rumenFragment());
        mFragment.add(new Train_cainiaoFragment());
        mFragment.add(new Train_jinjieFragment());

    }

}
